﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cancercurer
{
    class Neurone
    {
        private double[] entrees;
        private double[] poids;
        private double sortie;

        public Neurone(int nbEntrees)
        {
            entrees = new double[nbEntrees + 1];
            poids = new double[nbEntrees + 1];
            this.entrees[nbEntrees] = 1.0;
        }

        public void Initialize(Random rand)
        {
            for (int i = 0; i < poids.Length; i++)
            {
                poids[i] = rand.NextDouble() * 2 - 1.0;
            }
        }

        public double getSortie()
        {
            return sortie;
        }

        public double getPoids(int index)
        {
            return poids[index];
        }

        public void SetEntrees(double E1, double E2, double E3)
        {
            this.entrees[0] = E1;
            this.entrees[1] = E2;
            this.entrees[2] = E3;
        }

        public void SetEntree(int index, double E)
        {
            this.entrees[index] = E;
        }

        public double GetEntree(int index)
        {
            return this.entrees[index];
        }

        // Fonction d'agrégation
        public void Agregation()
        {
            double result = 0.0;

            for (int i = 0; i < poids.Length; i++)
            {
                result += entrees[i] * poids[i];
            }

            this.Activation(result);
        }

        // Fonction d'activation sigmoïde
        public void Activation(double x)
        {
            double result = 0;

            result = 1.0 / (1.0 + Math.Exp(x  * -1.0));

            this.sortie = result;
        }

        public void AjusterPoids(int index, double valeur)
        {
            poids[index] = valeur;
        }
    }
}
